package com.schoolcloud.social.controller.event;

import com.schoolcloud.common.model.R;
import com.schoolcloud.social.entity.EventCategory;
import com.schoolcloud.social.service.EventCategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/social/event/category")
@RequiredArgsConstructor
public class EventCategoryController {
    private final EventCategoryService eventCategoryService;
    @GetMapping("/list")
    public R<List<EventCategory>> getCategoryList() {
        return R.ok(eventCategoryService.list());
    }
    @PostMapping
    public R<?> addCategory(@RequestBody EventCategory eventCategory) {
        eventCategoryService.save(eventCategory);
        return R.ok().setMsg("添加成功");
    }
    @PutMapping
    public R<?> updateCategory(@RequestBody EventCategory eventCategory) {
        eventCategoryService.updateById(eventCategory);
        return R.ok().setMsg("修改成功");
    }
    @GetMapping("/{id}")
    public R<EventCategory> getCategory(@PathVariable Integer id) {
        return R.ok(eventCategoryService.getById(id));
    }
}
